﻿using RentAWorker.DataAccess;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using RentAWorker.DataAccess.Interfaces;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using RentAWorker.DataAccess.Entities;

namespace RentAWorker.DataAccess.Tests
{
    /// <summary>
    ///This is a test class for ResourceDataAccessTest and is intended
    ///to contain all ResourceDataAccessTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ResourceDataAccessTest
    {
        static CultureInfo deCulture;

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        
        [ClassInitialize()]
        public static void ResourceDataAccessTestInitialize(TestContext testContext)
        {
            deCulture = new CultureInfo("de-AT");
        
        }
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for UpdateResource
        ///</summary>
        [TestMethod()]
        public void UpdateResourceTest()
        {
            ResourceDataAccess target = new ResourceDataAccess(); // TODO: Initialize to an appropriate value
            RentResource updateResource = null; // TODO: Initialize to an appropriate value
            RentResource expected = null; // TODO: Initialize to an appropriate value
            RentResource actual;
            actual = target.UpdateResource(updateResource);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for GetResources
        ///</summary>
        [TestMethod()]
        public void GetResourcesTest1()
        {
            ResourceDataAccess target = new ResourceDataAccess(); // TODO: Initialize to an appropriate value
            string nameSearchPattern = string.Empty; // TODO: Initialize to an appropriate value
            IEnumerable<RentResource> expected = null; // TODO: Initialize to an appropriate value
            IEnumerable<RentResource> actual;
            actual = target.GetResources(nameSearchPattern);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for GetResources
        ///</summary>
        [TestMethod()]
        public void GetResourcesTest()
        {
            ResourceDataAccess target = new ResourceDataAccess(); // TODO: Initialize to an appropriate value
            IEnumerable<RentResource> expected = null; // TODO: Initialize to an appropriate value
            IEnumerable<RentResource> actual;
            actual = target.GetResources();
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for GetResource
        ///</summary>
        [TestMethod()]
        public void GetResourceTest()
        {
            ResourceDataAccess target = new ResourceDataAccess(); // TODO: Initialize to an appropriate value
            int resourceID = 0; // TODO: Initialize to an appropriate value
            RentResource expected = null; // TODO: Initialize to an appropriate value
            RentResource actual;
            actual = target.GetResource(resourceID);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for DeleteResource
        ///</summary>
        [TestMethod()]
        public void DeleteResourceTest()
        {
            ResourceDataAccess target = new ResourceDataAccess();
        }

        /// <summary>
        ///A test for CreateResource
        ///</summary>
        [TestMethod()]
        public void CreateResourceTest()
        {
            ResourceDataAccess target = new ResourceDataAccess(); // TODO: Initialize to an appropriate value

            RentResource newResource = new Worker()
            {
                Name = "Test Arbeiter",
                SSNo = "1234",
                Location = new LocationDataAccess().GetLocations("Innsbruck").First()
            };

            RentResource actual = target.CreateResource(newResource);

            Assert.IsNotNull(actual);
            Assert.IsInstanceOfType(actual, typeof(Worker));
        }

        /// <summary>
        ///A test for GetAvailableResources
        ///</summary>
        [TestMethod()]
        [DataSource("Provider=SQLOLEDB;Integrated Security=SSPI;Initial Catalog=BigDays2009-Tests;Data Source=(local)", "dbo.GetAvailableResourcesTest")]
        public void GetAvailableResourcesTest()
        {
            ResourceDataAccess target = new ResourceDataAccess();
            string nameSearchPattern = (string)GetDataByName("NameSearchPattern");
            DateTime fromDate = (DateTime)GetDataByName("FromDate");
            DateTime toDate = (DateTime)GetDataByName("ToDate");
            int locationId = (int)GetDataByName("LocationId");
            int? machineTypeId = null;

            int expectedCount = (int)GetDataByName("ExpectedCount");
            IEnumerable<RentResource> actual;

            actual = target.GetAvailableResources(nameSearchPattern, fromDate, toDate, locationId, machineTypeId);
            Assert.AreEqual(expectedCount, actual.Count());

            Assert.AreEqual(actual.All(p => p is Worker), true);
        }

        private object GetDataByName (string name)
        {
            return this.TestContext.DataRow[this.TestContext.DataRow.Table.Columns[name].Ordinal];
        }
    }
}
